package com.todo.strategy.online.application.api.controller;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.online.application.service.pipeline.PStrategyPipelineService;
import com.todo.strategy.online.service.api.pipeline.PStrategyPipelineApi;
import com.todo.strategy.online.service.api.pipeline.request.EnablePStrategyDetailRequest;
import com.todo.strategy.online.service.api.pipeline.request.InsertPStrategyDetailRequest;
import com.todo.strategy.online.service.api.pipeline.request.RemovePStrategyDetailRequest;
import com.todo.strategy.online.service.api.pipeline.request.UpdatePStrategyDetailRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/3/1 16:05
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/api/pipeline/pStrategy")
@Tag(name = "服务端-平台攻略同步接口", description = "服务端-平台攻略同步接口")
public class PStrategyPipelineApiController implements PStrategyPipelineApi {

    @Resource
    private PStrategyPipelineService pStrategyPipelineService;


    @Override
    @Operation(summary = "插入策略详情")
    @PostMapping("/insertPStrategyDetail")
    public BizResponse<Boolean> insertPStrategyDetail(@RequestBody InsertPStrategyDetailRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = pStrategyPipelineService.insertPStrategyDetail(request.getBusinessId(), request.getOriginData());
        return BizResponse.success(result);
    }

    @Override
    @Operation(summary = "更新策略详情")
    @PostMapping("/updatePStrategyDetail")
    public BizResponse<Boolean> updatePStrategyDetail(@RequestBody UpdatePStrategyDetailRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = pStrategyPipelineService.updatePStrategyDetail(request.getBusinessId(), request.getOriginData());
        return BizResponse.success(result);
    }

    @Override
    @Operation(summary = "删除策略详情")
    @PostMapping("/removePStrategyDetail")
    public BizResponse<Boolean> removePStrategyDetail(@RequestBody RemovePStrategyDetailRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = pStrategyPipelineService.removePStrategyDetail(request.getBusinessId());
        return BizResponse.success(result);
    }

    @Override
    @Operation(summary = "启/禁用策略详情")
    @PostMapping("/enablePStrategyDetail")
    public BizResponse<Boolean> enablePStrategyDetail(@RequestBody EnablePStrategyDetailRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = pStrategyPipelineService.enablePStrategyDetail(request.getBusinessId(), request.getOriginData());
        return BizResponse.success(result);
    }
}
